import { UserProfilesAPI } from "@/request/api";
export default {
  namespaced: true,
  state: {
    //购物车数量
    cartTotal: 0,
    userInfo: {
      nickName: "--",
      coin: "0",
      headImg: require("../../assets/img/userImg.f8bbec5e.png"),
    },
  },
  mutations: {
    //修改是否显示登录框状态
    updateUserInfo(state, payload) {
      // console.log(111, payload);
      state.cartTotal = payload.cartTotal;
      state.userInfo = payload.userInfo;
    },
    initUserInfo(state,payload){
      state.cartTotal= 0,
      state.userInfo= {
        nickName: "--",
        coin: "0",
        headImg: require("../../assets/img/userImg.f8bbec5e.png"),
      };
    },
  },
  actions: {
    async asyncChangeUserInfo(context) {
      let res = await UserProfilesAPI();
      // console.log("asyncChangeUserInfo:", res);
      context.commit("updateUserInfo", res.data);
    },
  },
};
